import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'https://key-nice-falcon.ngrok-free.app',
        secure: false,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
        // 增加重试和超时配置
        timeout: 30000,
        // 添加请求头以跳过ngrok浏览器警告和认证
        headers: {
          'ngrok-skip-browser-warning': 'true'
        }
      },
      '/video': {
        target: 'http://localhost:5173',
        secure: false,
        changeOrigin: true,
        ws: true,
        timeout: 30000
      }
    }
  }
})